package com.kime.email.javamail;

import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;

/**
 * 自定义验证器：实现 Authenticator 类，重写 getPasswordAuthentication() 方法
 */
public class MyAuthenticator extends Authenticator {

    private String sender;
    private String password;

    public MyAuthenticator() {
    }

    public MyAuthenticator(String sender, String password) {
        this.sender = sender;
        this.password = password;
    }

    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
        // 父类返回 null，自定义验证操作
        return new PasswordAuthentication(sender, password);
    }
}
